package view
{
import controller.ILoginWindowController;

import core.Context;

import model.entities.UserEntity;

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

/**
 * @author daichangxin
 */
public class LoginWindow extends Sprite
{
	private var _controller:ILoginWindowController;
	
	private var _messageText:TextField;
	
	public function LoginWindow(controller:ILoginWindowController)
	{
		_controller = controller;
		
		createUI();
		
		//test 点击登陆
		addEventListener(MouseEvent.CLICK, onMouseClick);
	}
	
	public function showLoginFail():void
	{
		var userEntity:UserEntity = Context.userModel.getUserEntity();
		
		_messageText.text = "loginFail, userName: " + userEntity.userName;
	}
	
	public function showLoginSuccess():void
	{
		var userEntity:UserEntity = Context.userModel.getUserEntity();
		_messageText.text = "loginSuccess, userName: " + userEntity.userName + ", level: " + userEntity.level;
	}
	
	private function onMouseClick(e:MouseEvent):void
	{
		trace("mouseClick from LoginWindow");
		_controller.onLoginButtonClick();
	}
	
	private function createUI():void
	{
		graphics.beginFill(0x808080);
		graphics.drawRect(0, 0, 300, 150);
		
		_messageText = new TextField();
		addChild(_messageText);
		_messageText.autoSize = TextFieldAutoSize.LEFT;
	}
	
	/**
	 * @return 输入的用户名
	 */
	public function get inputUserName():String
	{
		return "zhangSan";
	}
	
	/**
	 * @return 输入的密码
	 */
	public function get inputPassword():String
	{
		return "1234";
	}
}
}
